package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.jingjiu.homeservicesapi.domain.Order;
import com.jingjiu.homeservicesbiz.service.IOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通用订单主：记录收货信息、联系人等Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@Controller
@RequestMapping("/system/order")
public class OrderController extends BaseController
{

    @Autowired
    private IOrderService orderService;



    /**
     * 查询通用订单主：记录收货信息、联系人等列表
     */
    @RequiresPermissions("system:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Order order)
    {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    /**
     * 导出通用订单主：记录收货信息、联系人等列表
     */
    @RequiresPermissions("system:order:export")
    @Log(title = "通用订单主：记录收货信息、联系人等", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestBody Order order)
    {
        List<Order> list = orderService.selectOrderList(order);
        ExcelUtil<Order> util = new ExcelUtil<Order>(Order.class);
        return util.exportExcel(list, "通用订单主：记录收货信息、联系人等数据");
    }



    /**
     * 新增保存通用订单主：记录收货信息、联系人等
     */
    @RequiresPermissions("system:order:add")
    @Log(title = "通用订单主：记录收货信息、联系人等", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody Order order)
    {
        return toAjax(orderService.insertOrder(order));
    }

    /**
     * 修改通用订单主：记录收货信息、联系人等
     */
    @RequiresPermissions("system:order:edit")
    @GetMapping("/edit/{id}")
    public Order edit(@PathVariable("id") Long id)
    {
        Order order = orderService.selectOrderById(id);
        return  order;
    }

    /**
     * 修改保存通用订单主：记录收货信息、联系人等
     */
    @RequiresPermissions("system:order:edit")
    @Log(title = "通用订单主：记录收货信息、联系人等", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody Order order)
    {
        return toAjax(orderService.updateOrder(order));
    }

    /**
     * 删除通用订单主：记录收货信息、联系人等
     */
    @RequiresPermissions("system:order:remove")
    @Log(title = "通用订单主：记录收货信息、联系人等", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderService.deleteOrderByIds(ids));
    }
}
